package com.itheima.demo6;

public class Cook extends Thread {
    @Override
    public void run() {

        while (true){
            synchronized (Desk.lock){
                if (Desk.count == 0){
                    break;
                }else {
                    //判断是否有食物
                    if (Desk.foodFlog == 1){
                        try {
                            //有食物则进行等待
                            Desk.lock.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }else {
                        //制作食物
                        System.out.println("厨师做了一份食物");
                        Desk.foodFlog = 1;
                        //唤醒吃货
                        Desk.lock.notifyAll();
                    }
                }
            }
        }

    }
}
